package com.example.check_oa.model.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.comment_oa.pojos.MouthAt;
import com.example.comment_oa.pojos.attendance.MouthAtVo;
import com.example.check_oa.model.service.MouthAtService;
import com.example.check_oa.model.mapper.MouthAtMapper;
import com.example.check_oa.utils.GetAntten;
import com.example.comment_oa.util.EaxyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* @author cjl
* @description 针对表【mouth_at】的数据库操作Service实现
* @createDate 2023-01-19 12:28:17
*/
@Service
public class MouthAtServiceImpl extends ServiceImpl<MouthAtMapper, MouthAt>
    implements MouthAtService{
    @Resource
    MouthAtMapper mouthAtMapper;

    //每月一键归档
    @Override
    public int add(List<MouthAtVo> mouthAtVoList) {
        mouthAtVoList.forEach(e->{
            e.getAllVo().setMouth(e.getDate());//日期
            e.getAllVo().setUserMat(e.getUserNo());//工号
            e.getAllVo().setUserName(e.getUserName());//员工name
            e.getAllVo().setUserDept(e.getDept());//部门name
            e.getAllVo().setUserDeptId(e.getDeptId());//部门id
            e.getAllVo().setPostName(e.getPostName());//职位name
            e.getAllVo().setPostId(e.getPostId());//职位id
            e.getAllVo().setUserState(e.getUserState());//员工状态
            e.getAllVo().setSalaryIsClear(e.getSalaryIsClear());//是否结清
        });
        QueryWrapper<MouthAt> wrapper=new QueryWrapper<>();
        wrapper.like("mouth",mouthAtVoList.get(1).getDate());
        List<MouthAt> mouthAts = mouthAtMapper.selectList(wrapper);
//        EaxyUtils.write("哈哈1234",mouthAtVoList);
        if(mouthAts.isEmpty()){
            mouthAtVoList.forEach(e->{
                mouthAtMapper.insert(e.getAllVo());
            });
            return 1;
        }else{
            return 0;
        }
     }

    @Override
    public List<MouthAt> threMouthAt(String userNo) {
        List<String> stringList = GetAntten.threeMouth();
        List<MouthAt> mouthAts = mouthAtMapper.selectThreeMouth(userNo, stringList.get(0).substring(0,7));
        return mouthAts;
    }

}




